package com.minimalist.basic.controller.lindi;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.subsidyapplication.LindiSubsidyApplicationApprovalVO;
import com.minimalist.common.entity.lindi.vo.subsidyapplication.LindiSubsidyApplicationQueryVO;
import com.minimalist.common.entity.lindi.vo.subsidyapplication.LindiSubsidyApplicationVO;
import com.minimalist.common.feign.client.lindi.LindiSubsidyApplicationFeignClient;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * 林地指标交易平台_补贴申请控制器
 *
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_补贴申请管理")
@RequestMapping("/basic/lindi/subsidyApplication")
public class LindiSubsidyApplicationController{

    @Autowired
    private LindiSubsidyApplicationFeignClient feignClient;

    @PostMapping("/addSubsidyApplication")
    @Operation(summary = "添加补贴申请")
    @SaCheckPermission("lindi:subsidyApplication:add")
    public R<?> addSubsidyApplication(
            @RequestBody @Validated(Add.class) LindiSubsidyApplicationVO
                    subsidyApplicationVO){
        subsidyApplicationVO.setCreateId(StpUtil.getLoginIdAsLong());
        subsidyApplicationVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        subsidyApplicationVO.setCreateTime(now);
        subsidyApplicationVO.setUpdateTime(now);
        return feignClient.addSubsidyApplication(subsidyApplicationVO);
    }

    @DeleteMapping("/deleteSubsidyApplicationBySubsidyApplicationId")
    @Operation(summary = "删除补贴申请 -> 根据补贴申请ID删除")
    @SaCheckPermission("lindi:subsidyApplication:delete")
    public R<?> deleteSubsidyApplicationById(
            @RequestParam("subsidyApplicationId")
            @NotNull(message = "补贴申请ID不能为空")
            @Parameter(name = "subsidyApplicationId", required = true, description = "补贴申请ID")
            Long subsidyApplicationId){
        return feignClient.deleteSubsidyApplicationBySubsidyApplicationId(subsidyApplicationId);
    }

    @PutMapping("/updateSubsidyApplicationBySubsidyApplicationId")
    @Operation(summary = "修改补贴申请")
    @SaCheckPermission("lindi:subsidyApplication:update")
    public R<?> updateSubsidyApplicationBySubsidyApplicationId(
            @RequestBody @Validated(Update.class) LindiSubsidyApplicationVO
                    subsidyApplicationVO){
        subsidyApplicationVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        subsidyApplicationVO.setUpdateTime(now);
        return feignClient.updateSubsidyApplicationBySubsidyApplicationId(subsidyApplicationVO);
    }

    @GetMapping("/getPageSubsidyApplicationList")
    @Operation(summary = "查询补贴申请列表(分页)")
    @SaCheckPermission("lindi:subsidyApplication:get")
    public R<PageResp<LindiSubsidyApplicationVO>> getPageSubsidyApplicationList(
            LindiSubsidyApplicationQueryVO queryVO){
        return feignClient.getPageSubsidyApplicationList(queryVO);
    }

    @GetMapping("/getSubsidyApplicationBySubsidyApplicationId/{subsidyApplicationId}")
    @Operation(summary = "根据补贴申请ID查询补贴申请")
    @SaCheckPermission("lindi:subsidyApplication:get")
    public R<LindiSubsidyApplicationVO> getSubsidyApplicationBySubsidyApplicationId(
            @PathVariable(value = "subsidyApplicationId")
            @NotNull(message = "补贴申请ID不能为空")
            @Parameter(name = "subsidyApplicationId", description = "补贴申请ID", required = true)
            Long subsidyApplicationId){
        return feignClient.getSubsidyApplicationBySubsidyApplicationId(subsidyApplicationId);
    }

    @PostMapping("/approveSubsidyApplication")
    @Operation(summary = "审批补贴申请")
    @SaCheckPermission("lindi:subsidyApplication:approve")
    public R<?> approveSubsidyApplication(
            @RequestBody @Validated LindiSubsidyApplicationApprovalVO approvalVO){
        approvalVO.setUpdateId(StpUtil.getLoginIdAsLong());
        approvalVO.setUpdateTime(LocalDateTime.now());
        return feignClient.approveSubsidyApplication(approvalVO);
    }

    @PostMapping("/deleteSubsidyApplicationFileByFileId")
    @Operation(summary = "删除补贴申请文件 -> 根据文件ID删除")
    @SaCheckPermission("lindi:subsidyApplication:update")
    public R<?> deleteSubsidyApplicationFileByFileId(
            @RequestParam("fileId")
            @NotNull(message = "文件ID不能为空")
            @Parameter(name = "fileId", description = "文件ID", required = true)
            Long fileId){
        return feignClient.deleteSubsidyApplicationFileByFileId(fileId);
    }
}